package cn.group.controller;

import cn.group.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Controller
@RequestMapping("/user")
@SessionAttributes(value = {"user"})
public class UserController {
    private UserService userService;

    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    @ResponseBody
    @PostMapping("/login")
    public Map<String,Object> login(Model model, String username, String password, String role){
        //System.out.println(username);
        Map<String, Object> map = userService.userLogin(username, password, role);
        if((Integer)map.get("code")==0)
            model.addAttribute("user",map.get("user"));
        return map;
    }

    /*根据id修改用户的信息*/
    @GetMapping("/editUser")
    public String editStu(){
        return "editUser";
    }

    @GetMapping("/quit")
    public String logout(){
        return "login";
    }
}
